<template>
  <div>
    <div class="content">
      <p>
        收货人 ：
        <input type="text" placeholder="请输入姓名" v-model="information.name" />
      </p>
      <p>
        手机号 ：
        <input type="text" placeholder="请输入手机号" v-model="information.phone" />
      </p>
      <p>
        详细地址:
        <input type="text" placeholder="输入详细地址" v-model="information.address" />
      </p>
    </div>

    <b></b>
    <div class="sure" @click="addaddress">确定</div>
  </div>
</template>

<script>
import { Message } from 'element-ui'
import provinceAndCity from './province.json'
import { regionData, CodeToText } from 'element-china-area-data'
import {newAdd} from '../../api'
export default {
  data() {
    return {
      information: {
       
        name: '',
        phone: '',
        address: '',
      },
    
    }
  },

  methods: {
   addaddress(){
		 let str = this.huoqu();
		console.log("----->",str);
		let end1 = str.lastIndexOf('省') + 1;
		let end2 = str.lastIndexOf('市') + 1;
		let end3 = str.lastIndexOf('区') + 1;
		// let endStringPosition = equipmentImgUrl.lastIndexOf('.');
		let province = str.substring(0, end1);
		let city = str.substring(end1,end2);
		let area = str.substring(end2,end3);
		let addr = str.substring(end3)
		 console.log(this.information,'dssddd');
		 let uid = this.$store.state.uid
		 	newAdd({userId:uid,
			  area:area,
				  city:city,
					addr:addr,
						province:province,
						receiverMobile:this.information.phone,
					  receiverName:this.information.name,
						  status:this.information.status,
			 }).then(res => {
        console.log(res, 'edit')
        this.information = res.data.data
				if(res.data.code === 10000){
						// console.log("添加成功！！");
       Message({
        message: "添加成功",
        type: "success",
        duration: 2500
      })
			this.$router.push('/address')
				}else{
					  Message({
        message: "添加失败",
        type: "error",
        duration: 2500
      })
				}
		
			
      })
	 },
	 huoqu(){
			let str = this.information.address;
			return str;	
		}
  },
  mounted() {
   
}
}
</script>

<style scoped>
.content {
  width: 100vw;
  height: 50vh;
  /* background: pink; */
  font-size: 2.5vh;
}
p {
  border-bottom: 1px solid #eee;
  margin-left: 7vw;
}

input {
  width: 60vw;
  height: 5vh;
  outline: none;
  border: none;
  margin-top: 3vh;
}
.el-cascader {
  margin-top: 3vh;
}
.sure {
  width: 100vw;
  height: 10vh;
  background: #409eff;
  position: fixed;
  bottom: 0;
  text-align: center;
  line-height: 10vh;
  font-size: 20px;
  color: #fff;
}
</style>